﻿/// <reference path="D:\刘亚平Net资料\代码\私人代码\SmartForms\SmartForm2.0\SmartForm\SmartForm.Web\Scripts/jquery-1.7.2.min.js" />
/// <reference path="D:\刘亚平Net资料\代码\私人代码\SmartForms\SmartForm2.0\SmartForm\SmartForm.Web\Scripts/jquery.query.js" />
; (function ($) {
    var methods = {
        init: function (PowerJson) {
            $(this).find("[ITSM].wmpMultUserSelector").WmpSelect("user", { multy: true });//初始化 多选用户
            $(this).find("[ITSM].wmpSingleUserSelector").WmpSelect("user");//初始化 单选用户
            $(this).find("[ITSM].wmpSingleDeptSelector").WmpSelect("dept");//初始化 单选部门
            $(this).find("[ITSM][type=radioList] .container-radio").on("click", function () {
                if ($(this).parent().attr("disabled") != "disabled") {
                    $(this).siblings().find("a").removeClass("checked");
                    $(this).find("a").addClass("checked");
                }
            });
            ///初始化多选 控件
            $(this).find("[ITSM][type=checkboxlist] .container-radio").on("click", function () {
                if ($(this).parent("[type=checkboxlist]").attr("disabled") != "disabled") {
                    if ($(this).find("a").hasClass("checked")) {
                        $(this).find("a").removeClass("checked");
                    } else {
                        $(this).find("a").addClass("checked");
                    }
                }
            });

            $(this).find("[ITSM][type=datalist]").wmpDetail();
            $(this).find("[ITSM][type=Attachment]").wmpDetail();
            $(this).find("[dataJson]").each(function () {
                var detailConfig = JSON.parse(decodeURIComponent($(this).attr("dataJson")));
               
                if (detailConfig.ModelType != "DetailList")
                    return;
                var grid = $(this);
                if (detailConfig.EditType == "GridEdit") {
                    $(this).find(".ProcBtn .add").click(function () {
                        var rowdefaultdata = {};
                        for (var i = 0; i < detailConfig.ControlList.length; i++) {
                            var control = detailConfig.ControlList[i];
                            rowdefaultdata[control.ControlID] = "";
                            if (control.ControlExtend.DefaultValue != "" && control.ControlExtend.DefaultValue != undefined) {
                                rowdefaultdata[control.ControlID] = control.ControlExtend.DefaultValue;
                            }

                        }
                        grid.wmpDetail("add_row", rowdefaultdata);
                    });
                    $(this).find(".ProcBtn .del").click(function () {
                        var checkItemList = grid.find(".ckeckItem a.checked");
                        if (checkItemList.length < 1) {
                            parent.ShowError("请选择删除的行！");
                            return;
                        }
                        checkItemList.each(function () {
                            var trobj = $(this).parents("tr");
                            grid.wmpDetail("remove_row", trobj);
                        });
                    });
                    $(this).on("click", "a.Delete", function () {
                        var trobj = $(this).parents("tr");
                        grid.wmpDetail("remove_row", trobj);
                    });
                    $(this).find(".ProcBtn .import").click(function () {

                    });
                    $(this).find(".ProcBtn .export").click(function () {

                    });
                } else {
                    $(this).find(".ProcBtn .add").click(function () {
                        $(this).OpenSmartForm("addDetail");
                    });
                    $(this).find(".ProcBtn .del").click(function () {
                        var checkItemList = grid.find(".ckeckItem a.checked");
                        if (checkItemList.length < 1) {
                            parent.ShowError("请选择删除的行！");
                            return;
                        }
                        checkItemList.each(function () {
                            var trobj = $(this).parents("tr");
                            grid.wmpDetail("remove_row", trobj);
                        });
                    });
                    $(this).on("click", "a.Delete", function () {
                        var trobj = $(this).parents("tr");
                        grid.wmpDetail("remove_row", trobj);
                    });
                    $(this).on("click", "a.Edit", function () {
                        $(this).OpenSmartForm("editDetail");
                    });
                    $(this).find(".ProcBtn .import").click(function () {

                    });
                    $(this).find(".ProcBtn .export").click(function () {

                    });
                }
            });
            $(this).find("[ITSM][type=Attachment]").each(function () {
                var grid = $(this);
                $(this).find(".ProcBtn .add").AttachmentButton("init",{confirm:function(data){
                        grid.wmpDetail("add_row", data);
                }});
                $(this).find(".ProcBtn .del").click(function () {
                    var checkItemList = grid.find(".ckeckItem a.checked");
                    if (checkItemList.length < 1) {
                        parent.ShowError("请选择删除的行！");
                        return;
                    }
                    checkItemList.each(function () {
                        var trobj = $(this).parents("tr");
                        grid.wmpDetail("remove_row", trobj);
                    });
                });
                $(this).on("click", "a.Delete", function () {
                    var trobj = $(this).parents("tr");
                    grid.wmpDetail("remove_row", trobj);
                });
            });
            $(this).find("select[ITSM]").each(function () {
                var setting = {};
                switch ($(this).attr("EditType")) {
                    case "Single": setting.multy = false; break;
                    case "Multi": setting.multy = true; break;
                    case "SingleQuery": setting.multy = false; setting.search = true; break;
                    case "MultiQuery": setting.multy = true; setting.search = true; break;
                    default: setting.multy = false; break;
                }
                $(this).WmpSelectBox("init", setting);
            });
            $(this).find("[ITSM][type=project]").WmpSelect("project");
            $(this).find("[ITSM][type=cost]").WmpSelect("cost");
            $(this).find("[ITSM][itsmtype=TextDateTime]").wmpDate("calendar", {});
            function GetID() {
                return Number(Math.random().toString().substr(3, length) + Date.now()).toString(36);
            }
            $(this).find("[ITSM][itsmtype=editor]").each(function () {
                var plane = $(this).parent();
                var $this = $(this);
                if ($(this).attr("IsInit") == undefined) {
                    var editorID = "editor" + GetID();
                    plane.find(".editor").attr("id", editorID);
                    if (window.editor == undefined) {
                        window.editor = {};
                    }
                    // if (parent.UE != undefined) {
                    //     window.editor[$(this).attr("id")] = parent.UE.getEditor(editorID, {
                    //         initialFrameHeight: 200,
                    //         initialFrameWidth: "100%"
                    //     });
                    // } else {
                        window.editor[$(this).attr("id")] = UE.getEditor(editorID, {
                            initialFrameHeight: 200,
                            initialFrameWidth: "100%"
                        });
                    // }
                    //Ueditor
                    window.editor[$(this).attr("id")].addListener("blur", function (editor) {
                        $this.val(parent.UE.getEditor(editorID).getContent());
                    });
                    if ($this.val() != "") {
                        window.editor[$this.attr("id")].ready(function () {
                            window.editor[$this.attr("id")].setContent($this.val());
                        });
                    }
                    $(this).attr("IsInit", "1");
                }
            })
            function InputControl($this) {
                ////输入限制控制
                $this.on("keyup", "[InputType=1]", function () {
                    if (this.value.length == 1) { this.value = this.value.replace(/[^1-9]/g, '') } else { this.value = this.value.replace(/\D/g, '') };
                });
                $this.on("paste", "[InputType=1]", function () {
                    if (this.value.length == 1) { this.value = this.value.replace(/[^1-9]/g, '') } else { this.value = this.value.replace(/\D/g, '') }
                });
                ////输入限制控制
                $this.on("keyup", "[InputType=2]", function () {
                    var regStrs = [
                    ['^0(\\d+)$', '$1'], //禁止录入整数部分两位以上，但首位为0  
                    ['[^\\d\\.]+$', ''], //禁止录入任何非数字和点  
                    ['\\.(\\d?)\\.+', '.$1'], //禁止录入两个以上的点  
                    ['^(\\d+\\.\\d{2}).+', '$1'] //禁止录入小数点后两位以上  
                    ];
                    for (var i = 0; i < regStrs.length; i++) {
                        var reg = new RegExp(regStrs[i][0]);
                        this.value = this.value.replace(reg, regStrs[i][1]);
                    }
                });
                ////输入限制控制
                $this.on("onBlur", "[InputType=2]", function () {
                    var v = this.value;
                    if (v === '') {
                        v = '0.00';
                    } else if (v === '0') {
                        v = '0.00';
                    } else if (v === '0.') {
                        v = '0.00';
                    } else if (/^0+\d+\.?\d*.*$/.test(v)) {
                        v = v.replace(/^0+(\d+\.?\d*).*$/, '$1');
                        v = inp.getRightPriceFormat(v).val;
                    } else if (/^0\.\d$/.test(v)) {
                        v = v + '0';
                    } else if (!/^\d+\.\d{2}$/.test(v)) {
                        if (/^\d+\.\d{2}.+/.test(v)) {
                            v = v.replace(/^(\d+\.\d{2}).*$/, '$1');
                        } else if (/^\d+$/.test(v)) {
                            v = v + '.00';
                        } else if (/^\d+\.$/.test(v)) {
                            v = v + '00';
                        } else if (/^\d+\.\d$/.test(v)) {
                            v = v + '0';
                        } else if (/^[^\d]+\d+\.?\d*$/.test(v)) {
                            v = v.replace(/^[^\d]+(\d+\.?\d*)$/, '$1');
                        } else if (/\d+/.test(v)) {
                            v = v.replace(/^[^\d]*(\d+\.?\d*).*$/, '$1');
                            ty = false;
                        } else if (/^0+\d+\.?\d*$/.test(v)) {
                            v = v.replace(/^0+(\d+\.?\d*)$/, '$1');
                            ty = false;
                        } else {
                            v = '0.00';
                        }
                    }
                    this.value = v;
                });
                $this.on("paste", "[InputType=2]", function () {
                    return;
                });
                $this.on("keyup", "[InputType=3]", function () {
                    this.value = this.value.replace(/[^\a-\z\A-\Z]/g, '');
                })
                $this.on("paste", "[InputType=3]", function () {
                    this.value = this.value.replace(/[^\a-\z\A-\Z]/g, '');
                })
                $this.on("contextmenu", "[InputType=3]", function () {
                    this.value = this.value.replace(/[^\a-\z\A-\Z]/g, '');
                });
                $this.on("keyup", "[InputType=4]", function () {
                    this.value = this.value.replace(/[^d|chun]/g, '')
                })
                $this.on("keyup", "[InputType=5]", function () {
                    this.value = this.value.replace(/[^\u4E00-\u9FA5]/g, '')
                });
                $this.on("paste", "[InputType=5]", function () {
                    this.value = this.value.replace(/[^\u4E00-\u9FA5]/g, '');
                });
                $this.on("contextmenu", "[InputType=5]", function () {
                    this.value = this.value.replace(/[^\u4E00-\u9FA5]/g, '');
                });

            }
            InputControl($(this));
            var $this = $(this);
            if (PowerJson != undefined && PowerJson != "{}" && PowerJson != "" && (typeof (IsPower)=="undefined"|| IsPower != true)) {
                var powerConfig =typeof(PowerJson)=="string"?JSON.parse(decodeURIComponent(PowerJson)):PowerJson;
                for (var key in powerConfig) {
                    if(key.indexOf("@")>=0){
                        continue;
                    }
                    var modeltype = $this.find("#" + key).attr("modeltype");
                    if (modeltype == undefined)
                        continue;
                    if (modeltype == "BaseInfo") {
                        var BaseInfo = powerConfig[key].Children;
                        for (var baseInfoKey in BaseInfo) {
                            var itemBaseInfo = BaseInfo[baseInfoKey];
                            if (itemBaseInfo["IsEdit"] == "0" ||itemBaseInfo["Write"]==false) {
                                $this.find("#" + baseInfoKey).attr("disabled", "disabled");
                            }
                            if (itemBaseInfo["IsRequired"] == "1"||itemBaseInfo["Required"]==true) {
                                $($this.find("#" + baseInfoKey).parents(".controlcontent")[0]).addClass("flowrequired");
                            }
                            if (itemBaseInfo["Read"]==false) {
                                $this.find("#" + baseInfoKey).hide();
                            }
                        }
                        if (powerConfig[key].Read==false) {
                            $this.find("#" + key).hide();
                           $($this.find("#" + key).parents(".wbox")[0]).hide();
                        }
                    } else {
                        var BaseInfo = powerConfig[key].Children;
                        if (powerConfig[key]["IsOperationDetail"] == "1"||powerConfig[key]["IsOperationDetail"]==true) {
                            $this.find("#" + key).find(".ProcBtn").hide();
                            $this.find("#" + key).wmpDetail("hidden_column", ["operation"])
                        }
                        var readonlyList = [];
                        for (var baseInfoKey in BaseInfo) {
                            var itemBaseInfo = BaseInfo[baseInfoKey];
                            if (itemBaseInfo["IsEdit"] == "0" ||itemBaseInfo["Write"]==false) {
                                readonlyList.push(baseInfoKey);
                            }
                            if (itemBaseInfo["IsRequired"] == "1" ||itemBaseInfo["Required"]==true) {
                                $this.find("#" + key).find("[filed=" + baseInfoKey + "]").addClass("required");
                            }
                            // if (itemBaseInfo["Read"]==false) {
                            //     $this.find("#" + key).hide();
                            // }
                        }
                        $this.find("#" + key).wmpDetail("readonly_column", readonlyList);
                    }
                }
            }
        },///初始化

        setdata: function (fromData) {
            if (fromData == null || fromData == undefined) {
                return;
            }
            $(this).find("[ITSM]").each(function (i, o) {
                var control = $(this);
                if (control.length > 0) {
                    var ControlCode = $(this).attr("id").substring(3, $(this).attr("id").length);
                    var controlValue = fromData[ControlCode];
                    var controltype = control.attr("type") == undefined ? control[0].tagName.toLowerCase() : control.attr("type").toLowerCase();
                    if ("editor,wmpSelector".indexOf(control.attr("itsmtype")) >= 0) {
                        controltype = control.attr("itsmtype");
                    }
                    switch (controltype) {
                        case "editor":
                            control.val(controlValue);
                            window.editor[control.attr("id")].ready(function () {
                            window.editor[control.attr("id")].setContent(control.val());
                        });
                            break;
                        case "hidden": control.val(controlValue); break;
                        case "textarea":
                            control.val(controlValue);
                            break;
                        case "text":
                            control.val(controlValue);
                            var escapeVal = escape(controlValue).toLowerCase();
                            if (escapeVal.indexOf('%0a') > -1) {
                                control.attr("real-val", controlValue);
                            }
                            break;
                        case "number":
                        case "email":
                        case "month":
                        case "url": control.val(controlValue); break;
                        case "button": control.text(controlValue); break;
                            //case "select": control.selectpicker('val', controlValue); break;
                        case "select":
                            if (controlValue == undefined && controlValue == null) {
                                controlValue = fromData[ControlCode + "_value"];
                            } else {
                                controlValue = controlValue.value;
                            }
                            $(control).WmpSelectBox("set", controlValue);
                            //control.val(controlValue);
                            //control.attr("selectvalue", controlValue);
                            //control.WmpSelectpicker('init');
                            break;
                        case "radiolist":
                            if (controlValue == undefined && controlValue == null) {
                                controlValue = fromData[ControlCode + "_value"];
                            } else {
                                controlValue = controlValue.value;
                            }
                            $(control).find("a").removeClass("checked");
                            $(control).find("[value='" + controlValue + "']").addClass("checked");
                            //control.find("[type=radio]").removeAttr("checked");
                            //control.find("[value=" + controlValue + "]").click();
                            break;
                        case "checkboxlist":
                            if (controlValue == undefined && controlValue == null) {
                                controlValue = fromData[ControlCode + "_value"];
                            } else {
                                controlValue = controlValue.value;
                            }
                            var checkboxValues = controlValue.split(";");
                            $(control).find("a").removeClass("checked");
                            for (var idex = 0; idex < checkboxValues.length; idex++) {
                                if (checkboxValues[idex] != "")
                                    $(control).find("[value='" + checkboxValues[idex] + "']").addClass("checked");
                            }
                            break;
                        case "attachment": if (controlValue != undefined && controlValue != "" && controlValue != "undefined") {
                            if (controlValue.length > 0) {
                                $(control).wmpDetail("add_row", controlValue);
                            }
                        }
                            ///control.AttachmentGrid().LoadData(JSON.parse(decodeURIComponent(contorlValue)));
                            break;
                        case "datalist": if (controlValue != undefined && controlValue != "" && controlValue != "undefined") {
                            //$("#" + control.attr("id")).wmpOverTimeSelectorValue(JSON.parse(decodeURIComponent(controlValue)));
                            ///$("#" + control.attr("id")).WmpOvertime("set", JSON.parse(decodeURIComponent(controlValue)));
                            if (controlValue.length>0) {
                                $(control).wmpDetail("add_row", controlValue);
                                $(control).wmpDetail("readonly_column"); 
                            }
                        }
                            break;
                        case "wmpSelector":
                            //var text = $(fromData).find(control.attr("ControlCode") + "_" + $(smartThis).attr("id") + "_text").text().replace(/;/g, ",");
                            //var value = $(FromData).find(control.attr("ControlCode") + "_" + $(smartThis).attr("id") + "_value").text().replace(/;/g, ",");
                            if (controlValue == undefined && controlValue == null) {
                                controlValue = fromData[ControlCode + "_value"];
                                controlText = fromData[ControlCode + "_text"];
                            } else {
                                controlValue = controlValue.value;
                                controlText = controlValue.text;
                            }
                            if (controlValue != undefined && controlValue != null) {
                                var valarry = controlValue.split(';');
                                var testarry = controlValue.split(';');
                                var data = [];
                                for (var i = 0; i < valarry.length; i++) {
                                    data.push({ name: testarry[i], no: valarry[i] });
                                }
                                control.WmpSelect("set", data);
                            }
                            //var data = [];
                            //data.push(controlValue);
                            //control.WmpSelect("set", data);
                            break;
                        case "project":
                            var data = [];
                            data.push(controlValue);
                            control.WmpSelect("set", data);
                            break;
                        case "cost":
                            var data = [];
                            data.push(controlValue);
                            control.WmpSelect("set", data);
                            break;
                        case "label": control.text(controlValue); break;
                        default: break;
                    }

                }
            });
        },///赋值
        getdata: function () {
            var fromData = {};
            $(this).find("[ITSM]").each(function (idex) {
                var control = $(this);
                var ControlCode = control.attr("id").substring(3, control.attr("id").length);
                var controlValue = "";
                var controltype = control.attr("type") == undefined ? control[0].tagName.toLowerCase() : control.attr("type").toLowerCase();
                if ("editor,wmpSelector".indexOf(control.attr("itsmtype")) >= 0) {
                    controltype = control.attr("itsmtype");
                }
                switch (controltype) {
                    case "editor":
                    case "hidden":
                    case "textarea":
                    case "text":
                        controlValue = control.attr("real-val") || control.val();
                        break;
                    case "number":
                    case "email":
                    case "month":
                    case "url":
                    case "select":
                        var selectdataList = $(control).WmpSelectBox("get");
                        var valstr = "";
                        var textstr = "";
                        for (var i = 0; i < selectdataList.length; i++) {
                            valstr = valstr == "" ? selectdataList[i].value : valstr + "," + selectdataList[i].value;
                            textstr = textstr == "" ? selectdataList[i].text : textstr + "," + selectdataList[i].text;
                        }
                        controlValue = {}; controlValue.value = valstr, controlValue.text = textstr; break;
                    case "select-one": controlValue = {}; controlValue.value = control.val(); controlValue.text = control.find("option:selected").text(); break;
                    case "button": controlValue = control.text(); break;
                    case "radiolist": controlValue = {}; controlValue.value = control.find(".checked").length > 0 ? control.find(".checked").attr("value") : "";
                        controlValue.text = control.find(".checked").length > 0 ? control.find(".checked").parent().text() : ""; break;
                    case "checkboxlist":
                        controlValue = {};
                        var val = "";
                        var text = "";
                        control.find(".checked").each(function (idex) {
                            val = (val == "" ? $(this).attr("value") : val + ";" + $(this).attr("value"));
                            text = (text == "" ? $(this).parent().text() : text + ";" + $(this).parent().text());
                        });
                        controlValue.value = val;
                        controlValue.text = text;
                        break;
                    case "wmpSelector": ///选人 选择控件
                        var selectValueList = control.WmpSelect("get");
                        controlValue = {};
                        var val = "";
                        var text = "";
                        for(var i=0;i<selectValueList.length;i++){
                            val = (val == "" ? selectValueList[i].no : val + ";" + selectValueList[i].no);
                            text = (text == "" ? selectValueList[i].name : text + ";" + selectValueList[i].name);
                        };
                        controlValue.value = val;
                        controlValue.text = text;
                        break;
                    case "project":
                    case "cost":
                        controlValue = control.WmpSelect("get");
                        break;
                    case "datalist": ///明细列表控件
                        controlValue = control.wmpDetail("get");
                        break;
                    case "attachment": //附件控件
                        controlValue = control.wmpDetail("get");
                        break;
                    case "label": controlValue = control.text(); break;
                    default: break;
                }
                fromData[ControlCode] = controlValue;

            });
            return fromData;
        },//获取值
        getdefaultdata: function () {
            var fromData = {};
            $(this).find("[ITSM]").each(function (idex) {
                var control = $(this);
                var ControlCode = control.attr("id").substring(3, control.attr("id").length);
                var controlValue = "";
                var controltype = control.attr("type") == undefined ? control[0].tagName.toLowerCase() : control.attr("type").toLowerCase();
                if ("editor,wmpSelector".indexOf(control.attr("itsmtype")) >= 0) {
                    controltype = control.attr("itsmtype");
                }
                switch (controltype) {
                    case "editor":
                    case "hidden":
                    case "textarea":
                    case "text":
                        controlValue = control.attr("real-val") || control.val();
                        break;
                    case "number":
                    case "email":
                    case "month":
                    case "url":
                    case "select":
                        var selectdataList = $(control).WmpSelectBox("get");
                        var valstr = "";
                        var textstr = "";
                        for (var i = 0; i < selectdataList.length; i++) {
                            valstr = valstr == "" ? selectdataList[i].value : valstr + "," + selectdataList[i].value;
                            textstr = textstr == "" ? selectdataList[i].text : textstr + "," + selectdataList[i].text;
                        }
                        controlValue = {}; controlValue.value = valstr, controlValue.text = textstr; break;
                    case "select-one": controlValue = {}; controlValue.value = control.val(); controlValue.text = control.find("option:selected").text(); break;
                    case "button": controlValue = control.text(); break;
                    case "radiolist": controlValue = {}; controlValue.value = control.find(".checked").length > 0 ? control.find(".checked").attr("value") : "";
                        controlValue.text = control.find(".checked").length > 0 ? control.find(".checked").parent().text() : ""; break;
                    case "checkboxlist":
                        controlValue = {};
                        var val = "";
                        var text = "";
                        control.find(".checked").each(function (idex) {
                            val = (val == "" ? $(this).attr("value") : val + ";" + $(this).attr("value"));
                            text = (text == "" ? $(this).parent().text() : text + ";" + $(this).parent().text());
                        });
                        controlValue.value = val;
                        controlValue.text = text;
                        break;
                    case "wmpSelector": ///选人 选择控件
                        var selectValueList = control.WmpSelect("get");
                        controlValue = {};
                        var val = "";
                        var text = "";
                        for(var i=0;i<selectValueList.length;i++){
                            val = (val == "" ? selectValueList[i].no : val + ";" + selectValueList[i].no);
                            text = (text == "" ? selectValueList[i].name : text + ";" + selectValueList[i].name);
                        };
                        controlValue.value = val;
                        controlValue.text = text;
                        break;
                    case "project":
                    case "cost":
                        controlValue = control.WmpSelect("get");
                        break;
                    case "datalist": ///明细列表控件
                        var detailConfig = JSON.parse(decodeURIComponent(control.attr("dataJson")));
                        controlValue=[];
                        if (detailConfig.EditType == "GridEdit") {
                            var rowdefaultdata = {};
                            for (var i = 0; i < detailConfig.ControlList.length; i++) {
                                var control = detailConfig.ControlList[i];
                                rowdefaultdata[control.ControlID] = "";
                                if (control.ControlExtend.DefaultValue != "" && control.ControlExtend.DefaultValue != undefined) {
                                    rowdefaultdata[control.ControlID] = control.ControlExtend.DefaultValue;
                                }
                            }
                            controlValue.push(rowdefaultdata);
                        }else{
                            controlValue ="#【"+detailConfig.RefControlID+"】";
                        }

                        break;
                    case "attachment": //附件控件
                        controlValue = control.WmpAttachment("get");
                        break;
                    case "label": controlValue = control.text(); break;
                    default: break;
                }
                fromData[ControlCode] = controlValue;

            });
            return fromData;
        },//获取一个默认值，主要为了配置保存方法
        readonly: function (options) {
            $(this).find("[type=datalist]").wmpDetail("hidden_column", ["opration", "Opration", "Operation", "operation", "ckeckallradio"]);
            $(this).find("[type=datalist]").find("button").hide();
            $(this).find("[type=datalist]").wmpDetail("readonly");
            $(this).find("[type=cost]").WmpSelect("disabled");
            $(this).find("[type=project]").WmpSelect("disabled");
            $(this).find("[type=xselector]").WmpSelect("disabled");
            $(this).find("[type=text]").attr("disabled", "disabled");//-->导致明细在ie浏览器无法鼠标滚轮滚动的语句
            $(this).find("[type=select]").attr("disabled", "disabled");
            $(this).find("select").attr("disabled", "disabled");
            $(this).find("[type=radioList]").attr("disabled", "disabled");
            $(this).find("[type=checkboxlist]").attr("disabled", "disabled");
            $(this).find(".action [type]").removeAttr("disabled");///将流程平台操作按钮 设置为只读的改为可以触发事件
            $(this).find("textarea").attr("disabled", "disabled");
        },///通用验证方法
        bizformdata: function (IsRequired, PowerJson) {
            var isReturn = true;
            //var fromData = {};
            var $this = this;
            if (IsRequired == true) {
                $(this).find("[ITSM]").each(function (idex) {
                    var control = $(this);
                    var title = "";
                    var controlcontent = control.parents(".controlcontent");
                    if (controlcontent.prev().hasClass("controltitle")) {
                        title = controlcontent.prev().text();
                    } else {
                        title = control.attr("title");
                    }
                    var required = false;

                    required = IsRequired;

                    var ControlCode = control.attr("id").substring(3, control.attr("id").length);
                    var controlValue = "";
                    var controltype = control.attr("type") == undefined ? control[0].tagName.toLowerCase() : control.attr("type").toLowerCase();
                    if ("editor,wmpSelector".indexOf(control.attr("itsmtype")) >= 0) {
                        controltype = control.attr("itsmtype");
                    }
                    switch (controltype) {
                        case "editor":
                        case "hidden":
                        case "textarea":
                        case "text":
                            controlValue = control.attr("real-val") || control.val();
                            break;
                        case "number":
                        case "email":
                        case "month":
                        case "url":
                        case "select":
                            var selectdataList = $(control).WmpSelectBox("get");
                            var valstr = "";
                            var textstr = "";
                            for (var i = 0; i < selectdataList.length; i++) {
                                valstr = valstr == "" ? selectdataList[i].value : valstr + "," + selectdataList[i].value;
                                textstr = textstr == "" ? selectdataList[i].text : textstr + "," + selectdataList[i].text;
                            }
                            controlValue = {}; controlValue.value = valstr; controlValue.text = textstr;
                            if (controlValue.value == "" && required) {
                                parent.ShowError("字段【" + title + "】必填！");
                                isReturn = false;
                                return false;
                            }
                            break;
                        case "select-one": controlValue = {}; controlValue.value = control.val(); controlValue.text = control.find("option:selected").text();
                            if (controlValue.value == "" && required) {
                                parent.ShowError("字段【" + title + "】必填！");
                                isReturn = false;
                                return false;
                            }
                            break;
                        case "button": controlValue = control.text(); break;
                        case "radiolist": controlValue = {}; controlValue.value = control.find(".checked").length > 0 ? control.find(".checked").attr("value") : "";
                            controlValue.text = control.find(".checked").length > 0 ? control.find(".checked").parent().text() : "";
                            if (controlValue.value == "" && required) {
                                parent.ShowError("字段【" + title + "】必填！");
                                isReturn = false;
                                return false;
                            }
                            break;
                        case "checkboxlist":
                            controlValue = {};
                            var val = "";
                            var text = "";
                            control.find(".checked").each(function (idex) {
                                val = (val == "" ? $(this).attr("value") : val + ";" + $(this).attr("value"));
                                text = (text == "" ? $(this).parent().text() : text + ";" + $(this).parent().text());
                            });
                            controlValue.value = val;
                            controlValue.text = text;
                            if (controlValue.value == "" && required) {
                                parent.ShowError("字段【" + title + "】必填！");
                                isReturn = false;
                                return false;
                            }
                            break;
                        case "wmpSelector": ///选人 选择控件
                            var controlValue = control.WmpSelect("get");
                            if (controlValue.length == 0 && required) {
                                parent.ShowError("字段【" + title + "】必填！");
                                isReturn = false;
                                return false;
                            }
                            break;
                        case "project":
                        case "cost":
                            controlValue = control.WmpSelect("get");
                            if (controlValue.length == 0 && required) {
                                parent.ShowError("字段【" + title + "】必填！");
                                isReturn = false;
                                return false;
                            }
                            break;
                        case "datalist": ///明细列表控件
                            title = control.find(".nav-tabs-link").find(".form_info").text();
                            if (control.wmpDetail("get").length == 0 && required) {
                                parent.ShowError("明细控件【" + title + "】必须添加一行");
                                isReturn = false;
                                return false;
                            }
                            controlValue = encodeURIComponent(JSON.stringify(control.wmpDetail("get")));

                            break;
                        case "attachment": //附件控件
                            title = control.find(".nav-tabs-link").find(".form_info").text();
                            if (control.WmpAttachment("get").length == 0 && required) {
                                parent.ShowError("字段【" + title + "】必须添加一行");
                                isReturn = false;
                                return false;
                            }
                            controlValue = encodeURIComponent(JSON.stringify(control.WmpAttachment("get")));
                            break;
                        case "label": controlValue = control.text(); break;
                        default: break;
                    }
                    if (controlValue == "" && required&&controltype!="div") {
                        parent.ShowError("字段【" + title + "】必填！");
                        isReturn = false;
                        return false;
                    }
                    //fromData[ControlCode] = {}; 
                    //fromData[ControlCode]["value"] = controlValue;
                    //fromData[ControlCode]["title"] = title;
                });
            } else {
                if (PowerJson != undefined && PowerJson != "{}"&& PowerJson!="") {
                    var powerConfig = typeof (PowerJson) =="string"? JSON.parse(decodeURIComponent(PowerJson)):PowerJson;
                    for (var key in powerConfig) {
                        if(key.indexOf("@")>=0){
                            continue;
                        }
                        var modeltype = $this.find("#" + key).attr("modeltype");
                        if (modeltype == "BaseInfo") {
                            var BaseInfo = powerConfig[key].Children;
                            for (var baseInfoKey in BaseInfo) {
                                var itemBaseInfo = BaseInfo[baseInfoKey];
                                if (itemBaseInfo["IsRequired"] == "1"||itemBaseInfo["Required"]==true) {
                                    var ControlCode = baseInfoKey.substring(3, baseInfoKey.length);
                                    var control = $this.find("#" + baseInfoKey)
                                    var controlValue = "";
                                    var controltype = control.attr("type") == undefined ? control[0].tagName.toLowerCase() : control.attr("type").toLowerCase();
                                    if ("editor,wmpSelector".indexOf(control.attr("itsmtype")) >= 0) {
                                        controltype = control.attr("itsmtype");
                                    }
                                    switch (controltype) {
                                        case "editor":
                                        case "hidden":
                                        case "textarea":
                                        case "text":
                                            controlValue = control.attr("real-val") || control.val();
                                            break;
                                        case "number":
                                        case "email":
                                        case "month":
                                        case "url":
                                        case "select":
                                            var selectdataList = $(control).WmpSelectBox("get");
                                            var valstr = "";
                                            var textstr = "";
                                            for (var i = 0; i < selectdataList.length; i++) {
                                                valstr = valstr == "" ? selectdataList[i].value : valstr + "," + selectdataList[i].value;
                                                textstr = textstr == "" ? selectdataList[i].text : textstr + "," + selectdataList[i].text;
                                            }
                                            controlValue = {}; controlValue.value = valstr; controlValue.text = textstr;
                                            if (controlValue.value == "") {
                                                parent.ShowError("字段【" + itemBaseInfo.title.replace(/\+/g,"") + "】必填！");
                                                isReturn = false;
                                                return false;
                                            }
                                            break;
                                        case "select-one": controlValue = {}; controlValue.value = control.val(); controlValue.text = control.find("option:selected").text();
                                            if (controlValue.value == "") {
                                                parent.ShowError("字段【" + itemBaseInfo.title.replace(/\+/g, "") + "】必填！");
                                                isReturn = false;
                                                return false;
                                            }
                                            break;
                                        case "button": controlValue = control.text(); break;
                                        case "radiolist": controlValue = {}; controlValue.value = control.find(".checked").length > 0 ? control.find(".checked").attr("value") : "";
                                            controlValue.text = control.find(".checked").length > 0 ? control.find(".checked").parent().text() : "";
                                            if (controlValue.value == "") {
                                                parent.ShowError("字段【" + itemBaseInfo.title.replace(/\+/g, "") + "】必填！");
                                                isReturn = false;
                                                return false;
                                            }
                                            break;
                                        case "checkboxlist":
                                            controlValue = {};
                                            var val = "";
                                            var text = "";
                                            control.find(".checked").each(function (idex) {
                                                val = (val == "" ? $(this).attr("value") : val + ";" + $(this).attr("value"));
                                                text = (text == "" ? $(this).parent().text() : text + ";" + $(this).parent().text());
                                            });
                                            controlValue.value = val;
                                            controlValue.text = text;
                                            if (controlValue.value == "") {
                                                parent.ShowError("字段【" + itemBaseInfo.title.replace(/\+/g, "") + "】必填！");
                                                isReturn = false;
                                                return false;
                                            }
                                            break;
                                        case "wmpSelector": ///选人 选择控件
                                            var controlValue = control.WmpSelect("get");
                                            if (controlValue.length == 0) {
                                                parent.ShowError("字段【" + itemBaseInfo.title.replace(/\+/g, "") + "】必填！");
                                                isReturn = false;
                                                return false;
                                            }
                                            break;
                                        case "project":
                                        case "cost":
                                            controlValue = control.WmpSelect("get");
                                            if (controlValue.length == 0) {
                                                parent.ShowError("字段【" + itemBaseInfo.title.replace(/\+/g, "") + "】必填！");
                                                isReturn = false;
                                                return false;
                                            }
                                            break;
                                        case "datalist": ///明细列表控件
                                            title = control.find(".nav-tabs-link").find(".form_info").text();
                                            if (control.wmpDetail("get").length == 0) {
                                                parent.ShowError("明细控件【" + itemBaseInfo.title.replace(/\+/g, "") + "】必须添加一行");
                                                isReturn = false;
                                                return false;
                                            }
                                            controlValue = encodeURIComponent(JSON.stringify(control.wmpDetail("get")));

                                            break;
                                        case "attachment": //附件控件
                                            title = control.find(".nav-tabs-link").find(".form_info").text();
                                            if (control.WmpAttachment("get").length == 0) {
                                                parent.ShowError("字段【" + itemBaseInfo.title.replace(/\+/g, "") + "】必须添加一行");
                                                isReturn = false;
                                                return false;
                                            }
                                            controlValue = encodeURIComponent(JSON.stringify(control.WmpAttachment("get")));
                                            break;
                                        case "label": controlValue = control.text(); break;
                                        default: break;
                                    }
                                    if (controlValue == ""&&controltype!="div") {
                                        parent.ShowError("字段【" + itemBaseInfo.title.replace(/\+/g, "") + "】必填！");
                                        isReturn = false;
                                        return false;
                                    }
                                }
                            }
                        } else {
                            var detailList = $this.find("#" + key).wmpDetail("get");
                            if ((powerConfig[key]["IsDetailRequired"] == "1"||powerConfig[key]["IsDetailRequired"] ==true)&& detailList.length == 0) {
                                var detailTitle = powerConfig[key].title.replace(/\+/g, "");
                                detailTitle = detailTitle.split("(")[0];
                                parent.ShowError("明细控件【" + detailTitle + "】必须添加一行");
                                isReturn = false;
                                return false;
                            }
                            var BaseInfo = powerConfig[key].Children;
                            if (BaseInfo != undefined) {
                                if (JSON.stringify(BaseInfo).indexOf('"IsRequired":"1"') >= 0) {
                                    for (var i = 0; i < detailList.length; i++) {
                                        var itemdata = detailList[i];
                                        for (var datakey in itemdata) {
                                            if (powerConfig[key].Children[datakey] != null && powerConfig[key].Children[datakey] != undefined) {
                                                if ((powerConfig[key].Children[datakey]["IsRequired"] == 1||powerConfig[key].Children[datakey]["Required"] == true) && (itemdata[datakey] == "" || itemdata[datakey] == null)) {
                                                    var detailTitle = powerConfig[key].title.replace(/\+/g, "");
                                                    detailTitle = detailTitle.split("(")[0];
                                                    parent.ShowError("明细控件【" + detailTitle + "】第" + (i + 1) + "行字段【" + powerConfig[key].Children[datakey].title.replace(/\+/g, "") + "】必填");
                                                    isReturn = false;
                                                    return false;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //if (IsRequired == true) {
            //    return { isReturn: isReturn, fromData: fromData }
            //} else {
                return isReturn;
            //}
        }
    }
    $.fn.SmartFromData = function (method) {
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method' + method + 'does not exist');
        }
    };
})($);
